package com.tjetc.view;

import com.tjetc.domain.AdoptionApplication;
import com.tjetc.domain.History;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.ApplicationManageService;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

public class ApplicationManageView {
    private static Scanner sc=new Scanner(System.in);
    private ApplicationManageService applicationManageService= ClientProxy.getProxyInstance(ApplicationManageService.class);
    public void start() {
        while (true){
            System.out.println("1.待处理的领养申请列表");
            System.out.println("2.批准领养申请");
            System.out.println("3.拒绝领养申请");
            System.out.println("4.查看历史领养记录");
            System.out.println("0.返回上一级");
            System.out.println("请输入你的选择0~4");
            int i=sc.nextInt();
            switch (i){
                case 1:
                    list();
                    break;
                case 2:
                    approval();
                    break;
                case 3:
                    refuse();
                    break;
                case 4:
                    listAllHistory();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("请重新输入");
            }

        }
    }

    private void listAllHistory() {
        Result result=applicationManageService.listAllHistory();
        List<History> list=(List<History>) result.getData();
        if (list.size()>0){
            for (History history : list) {
                System.out.println(history);
            }
        }else {
            System.out.println("没有订单");
        }

    }

    private void refuse() {
        list();
        System.out.println("请输入想要拒绝的申请id");
        int id=sc.nextInt();
        Result result=applicationManageService.refuse(new AdoptionApplication().setId(id));
        System.out.println(result.getMsg());

    }

    private void approval() {
        list();
        System.out.println("请输入想要批准的申请id");
        int id= sc.nextInt();
        System.out.println("请输入评论");
        String comment= sc.next();
        Result result=applicationManageService.approval(new AdoptionApplication().setId(id).setComment(comment));
        System.out.println(result.getMsg());
    }

    private void list() {
        Result result=applicationManageService.list();
        List<AdoptionApplication> list=(List<AdoptionApplication>) result.getData();
        if (list.size()>0){
            for (AdoptionApplication list1 : list) {
                System.out.println(list1);
            }
        }else {
            System.out.println("没有需要批准的申请");
        }
    }
}
